﻿// Panner.cs (c) Copyright 2009, Mike Hodnick : www.hodnick.com
	
namespace Kindohm.KSynth.Library
{
    public class Panner : ISampleMaker, ISignalChainComponent
    {
        public ISampleMaker Output { get; set; }
        public ISampleMaker Input { get; set; }
        public short Pan { get; set; }

        public StereoSample GetSample()
        {
            StereoSample sample = this.Input.GetSample();
            double leftPercentage = 1;
            double rightPercentage = 1;

            if (this.Pan > 0)
                leftPercentage = (double)(short.MaxValue - this.Pan) / short.MaxValue;
            else if (this.Pan < 0)
                rightPercentage = (double)(short.MinValue - this.Pan) / short.MinValue;

            sample.LeftSample = (short)(sample.LeftSample * leftPercentage);
            sample.RightSample = (short)(sample.RightSample * rightPercentage);
            return sample;
        }
    }
}
